// src/models/Message.js
const mongoose = require('mongoose');

const messageSchema = new mongoose.Schema({
  from: { type: String, required: true },
  to: { type: String, required: true },
  scene: { type: String, enum: ['p2p', 'group'], required: true },
  type: { type: String, enum: ['text', 'image', 'video', 'file'], required: true },
  content: { type: String },
  file_url: { type: String },
  status: { type: String, enum: ['sent', 'delivered', 'read'], default: 'sent' },
  recalled: { type: Boolean, default: false },
  timestamp: { type: Date, default: Date.now },
  extra: { type: Object }
});

// 索引优化
messageSchema.index({ to: 1, timestamp: -1 });
messageSchema.index({ from: 1, timestamp: -1 });

module.exports = mongoose.model('Message', messageSchema);